package com.ohos.carbon.slice;

import com.ohos.carbon.ResourceTable;
import com.ohos.carbon.model.DemoDataBean;
import com.ohos.carbon.provider.BehaviorProvider;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.ListContainer;

import java.util.ArrayList;
import java.util.Map;

import static com.ohos.carbon.slice.MainAbilitySlice.pf;

public class BehaviorSlice extends AbilitySlice {
    private ListContainer list;
    private ArrayList<DemoDataBean> mList;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_behavior);
        initView();

        MainAbilitySlice.all = (Map<String, Integer>) pf.getAll();
        if (MainAbilitySlice.all.size() != 0) {
            if (MainAbilitySlice.all.containsKey("Behavior")) {
                for (Map.Entry<String, Integer> entry : MainAbilitySlice.all.entrySet()) {
                    if (entry.getKey().equals("Behavior")) {
                        int integer = entry.getValue();
                        integer++;
                        pf.putInt("Behavior", integer);
                        pf.flushSync();
                    }
                }
            } else {
                pf.putInt("Behavior", 1);
                pf.flushSync();
            }
        } else {
            pf.putInt("Behavior", 1);
            pf.flushSync();
        }
    }

    private void initView() {
        list = (ListContainer) findComponentById(ResourceTable.Id_list);
        mList = new ArrayList<>();
        mList.add(new DemoDataBean(ResourceTable.Media_randomdata_man0, "Doris Kathy Hall", null, null, null));
        mList.add(new DemoDataBean(ResourceTable.Media_randomdata_man1, "Janet Powell", null, null, null));
        mList.add(new DemoDataBean(ResourceTable.Media_randomdata_man2, "Jason Kelly", null, null, null));
        mList.add(new DemoDataBean(ResourceTable.Media_randomdata_man3, "Diana Julie Martinez", null, null, null));
        mList.add(new DemoDataBean(ResourceTable.Media_randomdata_man4, "Alice Hughes", null, null, null));
        mList.add(new DemoDataBean(ResourceTable.Media_randomdata_man5, "Kathy Deborah Stewart", null, null, null));
        mList.add(new DemoDataBean(ResourceTable.Media_randomdata_man6, "Adam Todd Patterson", null, null, null));
        mList.add(new DemoDataBean(ResourceTable.Media_randomdata_man7, "Dennis Hughes", null, null, null));
        mList.add(new DemoDataBean(ResourceTable.Media_randomdata_man8, "Clarence Jonathan Rogers", null, null, null));
        mList.add(new DemoDataBean(ResourceTable.Media_randomdata_man9, "Frances Stewart", null, null, null));
        list.setItemProvider(new BehaviorProvider(mList, getContext()));
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

}
